﻿
using LYR_RPA.models.project;
using System;
using System.Collections.Generic;

namespace LYR_RPA.utils
{
    public class SQLiteApply
    {
        /*
         * 读取全部项目
         */
        public static List<Folder> ReadProjects()
        {
            return DBUtils.Sqlite.Select<Folder>().ToList();
        }

        /*
         * 移除项目
         */
        public static bool RemoveProject(Project project)
        {
            
            return DBUtils.Sqlite.Insert(project).ExecuteAffrows() > 0;
        }

        /*
         * 查询添加的目录
         */
        public static List<Folder> SelectFolder()
        {
            return DBUtils.Sqlite.Select<Folder>().ToList();
        }

        /*
         * 查询移除的项目
         */
        public static List<Project> SelectRemoveProject()
        {
            return DBUtils.Sqlite.Select<Project>().ToList(); 
        }

        /*
         * 恢复项目
         */
        public static bool RecoverProject(Project project)
        {
            return DBUtils.Sqlite.Delete<Project>().Where(p => p.Path == project.Path).ExecuteAffrows() > 0;
        }

        /*
         * 移除目录
         */
        public static bool RemoveFolder(Project project)
        {
            return DBUtils.Sqlite.Delete<Folder>().Where(f => f.Path == project.Path).ExecuteAffrows()>0;
        }

        /*
         * 添加目录 
         */
        public static bool InsertFolder(Folder folder)
        {
            return DBUtils.Sqlite.Insert(folder).ExecuteAffrows()>0;
        }

        /*
         * 读取全部日志
         */
        public static List<Execute> ReadLogs()
        {
            return DBUtils.Sqlite.Select<Execute>().ToList();
        }

        /**
         * 清空日志
         */
        public static bool ClearLogs()
        {
            return DBUtils.Sqlite.Delete<Execute>().Where(e => e.Id>=0 || e.Id<0 ).ExecuteAffrows()>0;
        }

        /*
         * 插入日志
         */
        public static bool InsertLog(Execute execute)
        {
            return DBUtils.Sqlite.Insert(execute).ExecuteAffrows()>0;
        }

        
    }
}
